﻿using System;
using System.CodeDom.Compiler;
using System.Text;

namespace SharePoint.Orm.Metal.T4 {
	public class TemplateException : Exception {
		private readonly CompilerErrorCollection _errors;

		public TemplateException(CompilerErrorCollection errors)
			: base(GetMessage(errors)) {
			_errors = errors;
		}

		public CompilerErrorCollection Errors {
			get { return _errors; }
		}

		public static string GetMessage(CompilerErrorCollection errors) {
			StringBuilder result = new StringBuilder();
			result.AppendLine("Running template");
			foreach (CompilerError compilerError in errors) {
				result.AppendLine(compilerError.ToString());
			}
			return result.ToString();
		}
	}
}
